<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
    <meta http-equiv="expires" content="0">
    <!-- BEGIN 全局样式 -->
    <link rel="stylesheet" href="../../lib/bootstrap-3.3.7-dist/css/bootstrap.min.css" type="text/css"/>
    <link rel="stylesheet" href="../../css/reset-diy.css" type="text/css">
    <title>新增探霸</title>
    <style>
        .right-text {
            position: absolute;
            right: -17px;
            top: 8px;
        }
    </style>
</head>
<body>
<div class="container">

    <form id="formData" class="form-horizontal  mt-50 radius">
        <div class="mt-50">
            <div class="form-group">
                <label class="control-label col-sm-3">探霸地址</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control" name="mac" autocomplete="off" placeholder="探霸MAC地址">
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-sm-3">探霸分组</label>
                <div class="col-sm-6">
                    <select id="tb-group" class="form-control" name="type">
                        <option value="">--请选择--</option>
                        <option value="">大门</option>
                        <option value="">校内</option>
                    </select>
                </div>
            </div>
            <!--甲乙丙丁戊己庚辛壬癸-->
            <div class="form-group">
                <label class="control-label col-sm-3">探霸位置</label>
                <div class="col-sm-6">
                    <select id="tb-position" class="form-control" name="position">
                        <option value="">--请选择--</option>
                    </select>
                </div>
            </div>

        </div>
        <div class="form-group">
            <label class="control-label col-sm-3"></label>
            <div class="col-sm-6">
                <span class="btn btn-primary btn-submit">提交</span>
                <input class="btn btn-danger ml-15" type="reset" value="重置">
            </div>
        </div>

    </form>


</div>

<!--核心脚本sss-->
<script src="../../lib/jquery/1.9.1/jquery.js" type="text/javascript" charset="utf-8"></script>
<!--[if lt IE 9]>
<script src="../../js/excanvas.min.js"></script>
<script src="../../js/respond.min.js"></script>
<![endif]-->
<!--加密插件sss 必须放在jquery.myPlugIn_v1.0.js前面-->
<script src="../../js/common/jsrsasign-all-min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/common/crypto-js.min.js" type="text/javascript" charset="utf-8"></script>
<!--加密插件eee-->

<!--<script src="../../../js/bootstrap.min.js" type="text/javascript"></script>-->
<script src="../../lib/layer/2.4/layer.js" type="text/javascript" charset="utf-8"></script>
<!--<script src="../../../lib/laypage/1.2/laypage.js" type="text/javascript" charset="utf-8"></script>-->
<script src="../../js/work-box.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/common/jquery.myPlugIn_v1.0.js" type="text/javascript" charset="utf-8"></script>

<script>
    var T = new Extend_base();
    jQuery(document).ready(function () {
        function WarningCondition() {
            this.ClickEvent();
            this.getGroup();
            this.submitEvent();
        }

        WarningCondition.prototype = {
            data: [],
            ClickEvent: function () {
                var _this = this;
                $("#tb-group").on("change", function () {
                    var val = $(this).val();
                    _this.renderChild(val);
                });
            },
            getGroup: function () {
                var _this = this;
                T.ajaxTbManagePaging(url_join("admin/tanba/position"), "post", {id: T.getLocal("nId")}, function (res) {
                    _this.data = res.data;
                    _this.renderGroup(res.data);
                });
            },
            renderGroup: function (data) {
                var group = $("#tb-group");
                group.html("<option>--请选择--</option>");
                $.each(data, function (i, v) {
                    $('<option value="' + v.id + '">' + v.name + '</option>').appendTo(group);
                });
                var E = T.getSession('editData');
                $("#formData input[name=mac]").val(E.mac);
                this.renderCache(group,E.type);
                this.renderChild(E.type,E.position);
            },
            renderChild: function (val,ppp) {
                var _this = this;
                var position = $("#tb-position");
                position.html('<option>--请选择--</option>');
                $.each(_this.data, function (i, v) {
                    if (v.id == val) {
                        $.each(v.position, function (k, n) {
                            $('<option value="' + n.id + '">' + n.name + '</option>').appendTo(position);
                        });
                    }
                });
                ppp && this.renderCache(position,ppp);
            },
            renderCache:function (ele,num){
                var _this = this;
                ele.children("option").each(function (k,n){
                    if (n.value == num){
                        n.selected = "selected";
                    }
                });
            },
            submitEvent: function () {
                var _this = this;
                /*
                tb_id 探霸ID
                id 学校ID
                mac 探霸MAC地址
                type 探霸分组
                position 探霸位置 */

                $(".btn-submit").on("click", function (e) {
                    $("<input type='hidden' value='"+T.getLocal("nId")+"' name='id'>").prependTo($("#formData"));
                    $("<input type='hidden' value='"+T.getSession("editData").id+"' name='tb_id'>").prependTo($("#formData"));
                    T.ajaxTbManagePaging(url_join("admin/tanba/update"), "post", $("#formData").serializeObject(), function (e) {
                        layer.msg("操作成功", {icon: 1});
                        T.saveSession("refresh","true");
                        var index = parent.layer.getFrameIndex(window.name);
                        setTimeout(function (){
                            parent.layer.close(index);
                        },1000);
                    });
                });
            }
        };
        new WarningCondition();
    });
</script>
</body>
</html>